home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / ADisp_AGA.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-25  |  49.2 KB  |  1,993 lines

  1. /* $Id: $*/
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the Free
  19.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #include <gl/AmigaMesa.h>
  23. #ifdef    ADISP_AGA
  24.  
  25. #include "ADisp_AGA.h"
  26.  
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <gl/gl.h>
  30. #include "context.h"
  31. #include "dd.h"
  32. #include "xform.h"
  33. #include "macros.h"
  34. #include "vb.h"
  35.  
  36. #ifdef __GNUC__
  37. #include "../amiga/misc/ht_colors.h"
  38. #else
  39. #include "/amiga/misc/ht_colors.h"
  40. #endif
  41.  
  42. #include <exec/memory.h>
  43. #include <exec/types.h>
  44. #ifdef __GNUC__
  45. #include <inline/exec.h>
  46. #include <inline/intuition.h>
  47. #include <inline/graphics.h>
  48. #include <inline/utility.h>
  49. #else
  50. #include <proto/exec.h>
  51. #include <proto/intuition.h>
  52. #include <proto/graphics.h>
  53. #include <proto/utility.h>
  54. #endif
  55.  
  56. #ifdef AGA
  57. #define c8to32(x) ((x)<<24)
  58. #else
  59. #define c8to32(x) (((((((x)<<8)|(x))<<8)|(x))<<8)|(x))
  60. #endif
  61.  
  62. #define MAX_POLYGON 300
  63. //#define AGA 1
  64. // TrueColor-RGBA
  65. #define TC_RGBA(r,g,b,a) ((((((a<<8)|r)<<8)|g)<<8)|b)
  66.  
  67. //#define DEBUGPRINT
  68.  
  69. #ifdef DEBUGPRINT
  70. #define DEBUGOUT(x) printf(x);
  71. #else
  72. #define DEBUGOUT(x) /*printf(x);*/
  73. #endif
  74.  
  75. static void Amiga_Standard_resize_db( GLcontext *ctx,GLuint *width, GLuint *height);
  76. static void Amiga_Standard_resize( GLcontext *ctx,GLuint *width, GLuint *height);
  77.  
  78. struct RastPort *make_rastport( int width, int height, int depth, struct BitMap *friendbm );
  79. void destroy_rastport( struct RastPort *rp );
  80. BOOL make_temp_raster( struct RastPort *rp );
  81. void destroy_temp_raster( struct RastPort *rp );
  82. void AllocOneLine(struct amigamesa_context *AmigaMesaCreateContext);
  83. void FreeOneLine(struct amigamesa_context *AmigaMesaCreateContext);
  84.  
  85. BOOL alloc_temp_rastport(struct amigamesa_context * c);
  86. void free_temp_rastport(struct amigamesa_context * c);
  87.  
  88.  
  89. /*
  90. __inline int RGBA(GLubyte r,GLubyte g,GLubyte b,GLubyte a)
  91.     {
  92.     int pen;
  93.     
  94. *//*printf("RGBA(%d,%d,%d,%d)",r,g,b,a);getchar();*//*
  95.     pen=ObtainBestPen(amesa->Screen->ViewPort.ColorMap,
  96.             c8to32((ULONG)r),c8to32((ULONG)g),c8to32((ULONG)b),
  97.             OBP_Precision,PRECISION_GUI,TAG_DONE);
  98.     if(pen!=-1)
  99.         {
  100.         amesa->mypen[pen]+=1;
  101.         }
  102.     else
  103.         {
  104.         pen=FindColor(amesa->Screen->ViewPort.ColorMap,
  105.                                     c8to32((ULONG)r),c8to32((ULONG)g),c8to32((ULONG)b),-1); 
  106.                                     *//* If all pen is no sharable    take one */
  107. /* kprintf("(no sharable pen)\n",pen);*//*
  108.  
  109.         }
  110.     return pen;
  111.     }
  112. */ 
  113.  
  114. #define FIXx(x) (amesa->left + (x))
  115.  
  116. #define FIXy(y) (amesa->RealHeight-amesa->bottom - (y))
  117.  
  118. #define FIXxy(x,y) ((amesa->RealWidth*FIXy(y)+FIXx(x)))
  119.  
  120.  
  121. /**********************************************************************/
  122. /*****                Miscellaneous device driver funcs           *****/
  123. /**********************************************************************/
  124.  
  125. static void afinish( void )
  126. {
  127.     /* implements glFinish if possible */
  128. }
  129.  
  130.  
  131. static void aflush( void )
  132. {
  133.     /* implements glFlush if possible */
  134. }
  135.  
  136.  
  137. static void aclear_index( GLcontext *ctx, GLuint index )
  138. {
  139.    /* implement glClearIndex */
  140.    /* usually just save the value in the context struct */
  141.    /*printf("aclear_index=glClearIndex=%d\n",index);*/
  142.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  143.    amesa->clearpixel = amesa->penconv[index];
  144. }
  145.  
  146.  
  147. static void aclear_color( GLcontext *ctx,
  148.                           GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  149. {
  150.    /* implement glClearColor */
  151.    /* color components are floats in [0,1] */
  152.    /* usually just save the value in the context struct */
  153.    /*printf("aclear_color=glClearColor(%d,%d,%d,%d)\n",r,g,b,a);*/
  154.    /* @@@ TODO FREE COLOR IF NOT USED */
  155.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  156.    amesa->clearpixel=RGBA(amesa,r,g,b,a);
  157. /*  amesa->clearpixel=RGBA(r,g,b,a);  Orginal */  
  158.  
  159. }
  160.  
  161.  
  162.  
  163.  
  164. static void aclear( GLcontext *ctx,GLboolean all, GLint x, GLint y, GLint width, GLint height )
  165. {
  166. /*
  167.  * Clear the specified region of the color buffer using the clear color
  168.  * or index as specified by one of the two functions above.
  169.  * If all==GL_TRUE, clear whole buffer
  170.  */
  171.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  172.  
  173. #ifdef DEBUGPRINT
  174. printf("aclear(%d,%d,%d,%d,%d)\n",all,x,y,width,height);
  175. #endif
  176.  
  177.  
  178.     SetAPen(amesa->rp,amesa->clearpixel);
  179.     if(all)
  180.         {
  181.  
  182.         RectFill(amesa->rp,FIXx(ctx->Viewport.X),FIXy(ctx->Viewport.Y)-ctx->Viewport.Height+1,FIXx(ctx->Viewport.X)+ctx->Viewport.Width-1,FIXy(ctx->Viewport.Y));
  183.         if (amesa->visual->rgb_flag)
  184.             {
  185. /*
  186.             int I;
  187.             for(I=0;I<=255;I++) *//* Dealocate pens is in RGB mode *//*
  188.                 {
  189.                 while (amesa->mypen[I]!=0)          *//* TODO This may free some others pen also *//*
  190.                     {
  191.                     amesa->mypen[I]-=1;
  192.                     ReleasePen(amesa->Screen->ViewPort.ColorMap,I);
  193.                     }
  194.                 }
  195. */
  196.             }
  197.         }
  198.     else
  199.         {
  200.         if(amesa->rp!=0)
  201.             {
  202. /*      printf("RectFill(0x%x,%d,%d,%d,%d)\n",amesa->rp,FIXx(x),FIXy(y)-height,width,FIXy(y));*/
  203.             RectFill(amesa->rp,FIXx(x),FIXy(y)-height,width,FIXy(y));
  204.             }
  205.         else
  206.             printf("Serius error amesa->rp=0 detected in aclear() in file amigamesa.c\n");
  207.         }
  208.     
  209. }
  210.  
  211. static void aclear_db(GLcontext *ctx, GLboolean all, GLint x, GLint y, GLint width, GLint height )
  212. {
  213. /*
  214.  * Clear the specified region of the color buffer using the clear color
  215.  * or index as specified by one of the two functions above.
  216.  * If all==GL_TRUE, clear whole buffer
  217.  */
  218.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  219. /*  int i; */
  220.     register UBYTE *db;
  221.     register UBYTE col=amesa->clearpixel;
  222.  
  223.  
  224. #ifdef DEBUGPRINT
  225. printf("aclear_db(%d,%d,%d,%d,%d)\n",all,x,y,width,height);
  226. #endif
  227.  
  228.  
  229.  
  230. //  SetAPen(amesa->rp,amesa->clearpixel);
  231.     if(all)
  232.         {
  233.         int x1,y1,x2,y2;
  234. //      RectFill(amesa->rp,FIXx(CC.Viewport.X),FIXy(CC.Viewport.Y)-CC.Viewport.Height+1,FIXx(CC.Viewport.X)+CC.Viewport.Width-1,FIXy(CC.Viewport.Y));
  235.  
  236.         x1=0;
  237.         y1=0;
  238.         x2=amesa->RealWidth;
  239.         y2=amesa->RealHeight;
  240.         db=amesa->BackArray;
  241.         for(y1=0;y1<y2;y1++)
  242.             {
  243.             for(x1=0;x1<x2;x1++)
  244.                 {
  245.                 *db=col;
  246.                 db++;
  247.                 }
  248.             }
  249.         }
  250. //  return(((((amesa->RealWidth+15)>>4)<<4)*FIXy(y)+FIXx(x)));
  251.     else
  252.         {
  253.         int x1,y1,x2,y2;
  254. //      RectFill(amesa->rp,FIXx(x),FIXy(y)-height,width,FIXy(y));
  255.         x2=FIXx(x+width);
  256.         y2=FIXy(y);
  257.  
  258.         for(y1=FIXy(y)-height;y1<y2;y1++)
  259.             {
  260.             for(x1=FIXx(x);x1<x2;x1++)
  261.                 {
  262. //printf("clear byte 0x%x\n",&(amesa->BackArray[x1+y1*(((amesa->RealWidth+15)>>4)<<4)]));
  263.                 amesa->BackArray[x1+y1*amesa->RealWidth]=col;
  264.                 }
  265.             }
  266.         }
  267. }
  268.  
  269.  
  270.  
  271. static void aset_index( GLcontext *ctx,GLuint index )
  272. {
  273.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  274.  
  275.     /* Set the amesa color index. */
  276. /*printf("aset_index(%d)\n",index);*/
  277.     amesa->pixel = amesa->penconv[index];
  278. }
  279.  
  280.  
  281.  
  282. static void aset_color( GLcontext *ctx,GLubyte r, GLubyte g, GLubyte b, GLubyte a )
  283. {
  284.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  285.  
  286. /*printf("aset_color(%d,%d,%d,%d)\n",r,g,b,a);*/
  287.  
  288.         /* Set the current RGBA color. */
  289.         /* r is in 0..255.RedScale */
  290.         /* g is in 0..255.GreenScale */
  291.         /* b is in 0..255.BlueScale */
  292.         /* a is in 0..255.AlphaScale */
  293.     amesa->pixel = RGBA(amesa,r,g,b,a);
  294.     /*(a << 24) | (r << 16) | (g << 8) | b;*/
  295. }
  296.  
  297.  
  298. static GLboolean aindex_mask( GLcontext *ctx,GLuint mask )
  299. {
  300.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  301.  
  302.     /* implement glIndexMask if possible, else return GL_FALSE */
  303. /*printf("aindex_mask(0x%x)\n",mask);*/
  304.     amesa->rp->Mask = (UBYTE) mask;
  305.  
  306.     return(GL_TRUE);
  307. }
  308.  
  309. static GLboolean acolor_mask( GLcontext *ctx,GLboolean rmask, GLboolean gmask,
  310.                                       GLboolean bmask, GLboolean amask)
  311. {
  312.     /* implement glColorMask if possible, else return GL_FALSE */
  313.     return(GL_FALSE);
  314.  
  315. }
  316.  
  317.  
  318.  
  319. /**********************************************************************/
  320. /*****            Accelerated point, line, polygon rendering        *****/
  321. /**********************************************************************/
  322.  
  323. /*
  324.  *  Render a number of points by some hardware/OS accerated method
  325.  */
  326.  
  327. static void afast_points_function(GLcontext *ctx,GLuint first, GLuint last )
  328. {
  329.  
  330.  
  331.     AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  332.     struct vertex_buffer *VB = ctx->VB;
  333.  
  334.     int i,col;
  335.     register struct RastPort * rp=amesa->rp;
  336. /* printf("afast_points_function\n");*/
  337.  
  338.         if (VB->MonoColor) {
  339.         /* draw all points using the current color (set_color) */
  340.         SetAPen(rp,amesa->pixel);
  341. /*      printf("VB->MonoColor\n");*/
  342.         for (i=first;i<=last;i++) {
  343.             if (VB->Unclipped[i]) {
  344.                 /* compute window coordinate */
  345.                 int x, y;
  346.                 x =FIXx((GLint) (VB->Win[i][0]));
  347.                 y =FIXy((GLint) (VB->Win[i][1]));
  348.             WritePixel(rp,x,y);
  349. /*      printf("WritePixel(%d,%d)\n",x,y);*/
  350.             }
  351.         }
  352.     } else {
  353.         /* each point is a different color */
  354. /*      printf("!VB.MonoColor\n");*/
  355.  
  356.         for (i=first;i<=last;i++) {
  357.             /*if (VB.Unclipped[i])*/ {
  358.                 int x, y;
  359.                 x =FIXx((GLint) (VB->Win[i][0]));
  360.                 y =FIXy((GLint) (VB->Win[i][1]));
  361.                 col=*VB->Color[i];
  362.                 SetAPen(rp,amesa->penconv[col]);
  363.             WritePixel(rp,x,y);
  364. /*      printf("WritePixel(%d,%d)\n",x,y);*/
  365.             }
  366.         }
  367.     }
  368. }
  369.  
  370.  
  371.  
  372. static points_func achoose_points_function( GLcontext *ctx )
  373. {
  374. /*printf("achoose_points_function\n");*/
  375.     /* Examine the current rendering state and return a pointer to a */
  376.     /* fast point-rendering function if possible. */
  377.    if (ctx->Point.Size==1.0 && !ctx->Point.SmoothFlag && ctx->RasterMask==0
  378.        && !ctx->Texture.Enabled /*&&  ETC, ETC */) {
  379.       return afast_points_function;
  380.    }
  381.    else {
  382.       return NULL;
  383.    }
  384. }
  385.  
  386. static points_func achoose_points_function_db( GLcontext *ctx )
  387.     {
  388.     return NULL;
  389.     }
  390.  
  391.  
  392.  /*
  393.   *  Render a line by some hardware/OS accerated method 
  394.   */
  395.  
  396. static void afast_line_function( GLcontext *ctx,GLuint v0, GLuint v1, GLuint pv )
  397. {
  398.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  399.    struct vertex_buffer *VB = ctx->VB;
  400.     int x0, y0, x1, y1;
  401. /* printf("afast_line_function\n");*/
  402.  
  403.     if (VB->MonoColor)
  404.         {
  405.         SetAPen(amesa->rp,amesa->pixel);
  406.         }
  407.     else
  408.         {
  409.         SetAPen(amesa->rp,amesa->penconv[*VB->Color[pv]]);
  410.         }
  411.     x0 = FIXx((int) (VB->Win[v0][0]));
  412.     y0 = FIXy((int) (VB->Win[v0][1]));
  413.     x1 = FIXx((int) (VB->Win[v1][0]));
  414.     y1 = FIXy((int) (VB->Win[v1][1]));
  415.  
  416.     Move(amesa->rp,x0,y0);
  417.     Draw(amesa->rp,x1,y1);
  418. }
  419.  
  420.  
  421.  
  422. static line_func achoose_line_function( GLcontext *ctx)
  423. {
  424.     /*printf("achoose_line_function\n");*/
  425.  
  426.     /* Examine the current rendering state and return a pointer to a */
  427.     /* fast line-rendering function if possible. */
  428.  
  429.    if (ctx->Line.Width==1.0 && !ctx->Line.SmoothFlag && !ctx->Line.StippleFlag
  430.        && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
  431.        && !ctx->Texture.Enabled /*&&  ETC, ETC */ )
  432.         {
  433.         return afast_line_function;
  434.         }
  435.     else 
  436.         {
  437.  
  438.         return NULL;
  439.         }
  440. }
  441.  
  442. static line_func achoose_line_function_db( GLcontext *ctx)
  443.     {
  444.     return NULL;
  445.     }
  446.  
  447. /*
  448.  * Draw a filled polygon of a single color. If there is hardware/OS support
  449.  * for polygon drawing use that here.   Otherwise, call a function in
  450.  * polygon.c to do the drawing.
  451.  */
  452.  
  453. static void afast_polygon_function( GLcontext *ctx,GLuint n, GLuint vlist[], GLuint pv )
  454. {
  455.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  456.     struct vertex_buffer *VB = ctx->VB;
  457.  
  458.     int i,j;
  459.     struct RastPort * rp=amesa->rp;
  460.  
  461.     /* Render a line by some hardware/OS accerated method */
  462.     /* printf("afast_polygon_function\n");*/
  463.  
  464.     if (VB->MonoColor)
  465.         SetAPen(rp,amesa->pixel);
  466.     else
  467.         SetAPen(rp,amesa->penconv[*VB->Color[pv]]);
  468.  
  469.  
  470.     AreaMove(rp, FIXx((int) VB->Win[0][0]), FIXy( (int) VB->Win[0][1]));
  471.  
  472.  
  473.     for (i=1;i<n;i++) {
  474.         j=vlist[i];
  475.         AreaDraw(rp, FIXx((int) VB->Win[j][0]), FIXy( (int) VB->Win[j][1]));
  476.  
  477.     }
  478.     AreaEnd(rp );
  479. }
  480.  
  481.  
  482.  
  483.  
  484.  
  485. static polygon_func achoose_polygon_function( GLcontext *ctx )
  486. {
  487.     /* printf("achoose_polygon_function\n");*/
  488.  
  489.     /* Examine the current rendering state and return a pointer to a */
  490.     /* fast polygon-rendering function if possible. */
  491.  
  492.    if (!ctx->Polygon.SmoothFlag && !ctx->Polygon.StippleFlag
  493.        && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
  494.        && !ctx->Texture.Enabled /*&&  ETC, ETC */ )
  495.       {
  496.         return afast_polygon_function;
  497.         }
  498.     else 
  499.         {
  500.         return NULL;
  501.         }
  502. }
  503.  
  504. /**********************************************************************/
  505. /*****                  Optimized polygon rendering               *****/
  506. /**********************************************************************/
  507.  
  508. /* Outcomment all*/
  509.  
  510. /*
  511.  * Useful macros:
  512.  */
  513. /*
  514. #define PACK_RGBA(R,G,B,A)  (((R) << 24) | ((G) << 16) | ((B) << 8) | (A))
  515. #define PACK_ABGR(R,G,B,A)  (((A) << 24) | ((B) << 16) | ((G) << 8) | (R))
  516. *//*
  517. #define PACK_RGBA(R,G,B,A) RGBA(amesa,R,G,B,A)*/
  518. //#define PACK_ABGR(R,G,B,A) RGBA(R,G,B,A)
  519.  
  520. /* Help to fix this orginal in the top
  521. __inline GLint FIXx(GLint x)    return(amesa->left + x);
  522. __inline GLint FIXy(GLint y)    return(amesa->RealHeight-amesa->bottom - y);
  523. __inline GLint FIXxy(GLint x,GLint y) return((amesa->FixedWidth*FIXy(y)+FIXx(x)));
  524.         db=(ULONG)(amesa->BackArray)+(ULONG)FIXxy(x1,y1);
  525.  
  526. */
  527.  
  528. /*                                       
  529. #define PIXELADDR1(X,Y)  ((GLubyte *)  amesa->buffer +  (Y)*amesa->width + (X))
  530. #define PIXELADDR4(X,Y)   ((GLuint *)  amesa->buffer +  (Y)*amesa->width + (X))
  531. #define PIXELADDR4B(X,Y)  ((GLubyte *) amesa->buffer + ((Y)*amesa->width + (X))*4)
  532. */
  533.  
  534. /*#define PIXELADDR1(X,Y)  ((GLubyte *)  (amesa->BackArray) + FIXxy(X,Y))
  535. #define PIXELADDR4(X,Y)   ((GLuint *)  (amesa->BackArray) + FIXxy(X,Y))*/
  536. //#define PIXELADDR4B(X,Y)  ((GLubyte *) (amesa->BackArray) + FIXxy(X,Y)*4)
  537.  
  538.  
  539.  
  540. /*static GLint lx[MAX_HEIGHT], rx[MAX_HEIGHT];*/    /* X bounds */
  541. /*static GLfixed lz[MAX_HEIGHT], rz[MAX_HEIGHT];*/  /* Z values */
  542. /*static GLfixed lr[MAX_HEIGHT], rr[MAX_HEIGHT];*/  /* Red */
  543. /*static GLfixed lg[MAX_HEIGHT], rg[MAX_HEIGHT];*/  /* Green */
  544. /*static GLfixed lb[MAX_HEIGHT], rb[MAX_HEIGHT];*/  /* Blue */
  545. /*static GLfixed la[MAX_HEIGHT], ra[MAX_HEIGHT];*/  /* Alpha */
  546.  
  547.  
  548.  
  549. /*
  550.  * Smooth-shaded, z-less polygon, RGBA byte order.
  551.  */
  552. /*static void smooth_RGBA_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  553. {
  554. #define INTERP_COLOR
  555. #define INTERP_ALPHA
  556. #define INTERP_Z
  557.  
  558. #define INNER_CODE                      \
  559.    GLint i;                         \
  560.    GLubyte *img = PIXELADDR4(xmin,y);                   \
  561.    for (i=0;i<len;i++) {                    \
  562.       if (FixedToUns(fz) < *zptr) {             \
  563.          *img = PACK_RGBA( FixedToInt(fr), FixedToInt(fg),  \
  564.                    FixedToInt(fb), FixedToInt(fa) );    \
  565.          *zptr = FixedToUns(fz);                \
  566.       }                             \
  567.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;  fa += fdadx;    \
  568.       fz += fdzdx;  zptr++;  img++;             \
  569.    }
  570.  
  571. #include "polytemp.h"
  572. }
  573.  
  574.  
  575.  
  576. */
  577. /*
  578.  * Smooth-shaded, z-less polygon.
  579.  */
  580. /*static void flat_RGBA_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  581. {
  582. #define INTERP_COLOR
  583. #define INTERP_ALPHA
  584. #define INTERP_Z
  585.  
  586. #define SETUP_CODE          \
  587.    GLubyte r = VB.Color[pv][0];     \
  588.    GLubyte g = VB.Color[pv][1];     \
  589.    GLubyte b = VB.Color[pv][2];     \
  590.    GLubyte a = VB.Color[pv][3];     \
  591.    GLubyte pixel = PACK_RGBA(r,g,b,a );
  592.  
  593. #define INNER_CODE          \
  594.    GLint i;             \
  595.    GLubyte *img = PIXELADDR4(xmin,y);       \
  596.    for (i=0;i<len;i++) {        \
  597.       if (FixedToUns(fz) < *zptr) { \
  598.      *img = pixel;          \
  599.          *zptr = FixedToUns(fz);    \
  600.       }                 \
  601.       fz += fdzdx;  zptr++;  img++; \
  602.    }
  603.  
  604. #include "polytemp.h"
  605. }
  606.  
  607.  
  608.  
  609. *//*
  610.  * Return pointer to an accelerated polygon function if possible.
  611.  */
  612. /*static polygon_func choose_polygon_function_os( GLcontext *ctx)
  613. {
  614.    GLuint i4 = 1;
  615.    GLubyte *i1 = (GLubyte *) &i4;
  616.    GLint little_endian = *i1;
  617.  
  618.    if (CC.Polygon.SmoothFlag)     return NULL;
  619.    if (CC.Polygon.StippleFlag)    return NULL;
  620.    if (CC.Texture.Enabled)        return NULL;
  621.  
  622.    if (CC.RasterMask==DEPTH_BIT
  623.        && CC.Depth.Func==GL_LESS
  624.        && CC.Depth.Mask==GL_TRUE
  625. *//*     && amesa->format==GL_RGBA*//*) {
  626.       if (CC.Light.ShadeModel==GL_SMOOTH) {
  627.          if (little_endian) {
  628.             return smooth_ABGR_z_polygon;
  629.          }
  630.          else {
  631.             return smooth_RGBA_z_polygon;
  632.          }
  633.       }
  634.       else {
  635.          return flat_RGBA_z_polygon;
  636.       }
  637.    }
  638.    return NULL;
  639. }
  640.  
  641. END outcomment all*/ 
  642.  
  643.  
  644. static polygon_func achoose_polygon_function_db( GLcontext *ctx )
  645. {
  646.     return NULL;
  647. }
  648.  
  649.  
  650. /**********************************************************************/
  651. /*****              Write spans of pixels                                   *****/
  652. /**********************************************************************/
  653.  
  654. static void awrite_index_span_db(GLcontext *ctx, GLuint n, GLint x, GLint y,
  655.                                             const GLuint index[],
  656.                                             const GLubyte mask[] )
  657. {
  658.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  659.  
  660.     int i/* ,ant*/;
  661.     register UBYTE *db;
  662.     register unsigned long * penconv=amesa->penconv;
  663.  
  664.  
  665. #ifdef DEBUGPRINT
  666. printf("awrite_index_span_db(%d,%d,%d)\n",n,x,y);
  667. #endif
  668.  
  669. db=amesa->BackArray+FIXxy(x,y);
  670.  
  671.     /* Slower */
  672.     if(mask)
  673.         {
  674.         for (i=0;i<n;i++)
  675.             {
  676.             if(mask[i])
  677.                 {
  678.                 /* draw pixel (x[i],y[i]) using index[i] */
  679.                 *db=penconv[index[i]];
  680.                 }
  681.                 db++;
  682.             }
  683.         }
  684.     else
  685.         for (i=0;i<n;i++)
  686.             {
  687.             /* draw pixel (x[i],y[i]) using index[i] */
  688.             *db=penconv[index[i]];
  689.             db++;
  690.             }
  691.     }
  692.  
  693. static void awrite_color_span_db(GLcontext *ctx, GLuint n, GLint x, GLint y,
  694.                                         const GLubyte red[], const GLubyte green[],
  695.                                         const GLubyte blue[], const GLubyte alpha[],
  696.                                         const GLubyte mask[])
  697. {
  698.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  699.     int i/*,ant*/;
  700.     register UBYTE *db;
  701.  
  702. #ifdef DEBUGPRINT
  703. printf("awrite_color_span_db(%d,%d,%d)\n",n,x,y);
  704. #endif
  705.  
  706. db=amesa->BackArray+FIXxy(x,y);
  707. /* Slower */
  708.     if (mask)
  709.         {
  710.         for (i=0;i<n;i++)
  711.             {
  712.             if (mask[i])
  713.                 {
  714.                 /* draw pixel (x[i],y[i]) using index[i] */
  715.                 *db=RGBA(amesa,red[i],green[i],blue[i],alpha[i]);
  716.                 }
  717.             db++;
  718.             }
  719.         }
  720.     else
  721.         {
  722.         for (i=0;i<n;i++)
  723.             {
  724.             /* draw pixel (x[i],y[i]) using index[i] */
  725.             *db=RGBA(amesa,red[i],green[i],blue[i],alpha[i]);
  726.             db++;
  727.             }
  728.         }
  729.     
  730. }
  731. static void awrite_monoindex_span_db( GLcontext *ctx,GLuint n, GLint x, GLint y,
  732.                                              const GLubyte mask[])
  733. {
  734.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  735.     int i/*,ant*/;
  736.     register UBYTE *db;
  737.  
  738. #ifdef DEBUGPRINT
  739. printf("awrite_monoindex_span_db(%d,%d,%d)\n",n,x,y);
  740. #endif
  741.  
  742. db=amesa->BackArray+FIXxy(x,y);
  743.  
  744.     /* Slower */
  745. if(mask)
  746.     {
  747.     for (i=0;i<n;i++)
  748.         {
  749.         if (mask[i])
  750.             {
  751.             /* draw pixel (x[i],y[i]) using index[i] */
  752.             *db=amesa->pixel;
  753.             }
  754.         db++;
  755.         }
  756.     }
  757. else
  758.     for (i=0;i<n;i++)
  759.         {
  760.         /* draw pixel (x[i],y[i]) using index[i] */
  761.         *db=amesa->pixel;
  762.         db++;
  763.         }
  764. }
  765.  
  766.  
  767. static void awrite_index_span(GLcontext *ctx, GLuint n, GLint x, GLint y,
  768.                                         const GLuint index[],
  769.                                         const GLubyte mask[] )
  770. {
  771.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  772.     int i,ant;
  773.     UBYTE *dp;
  774.     unsigned long * penconv=amesa->penconv;
  775.     register struct RastPort * rp=amesa->rp;
  776.  
  777. /*printf("awrite_index_span(%d,%d,%d)\n",n,x,y);*/
  778. DEBUGOUT("awrite_index_span(n,x,y)\n")
  779.  
  780.     y=FIXy(y);
  781.     x=FIXx(x);
  782.     /* JAM: Added correct checking */
  783.     /* if((dp = amesa->imageline) && amesa->tmpras) */
  784.     if((dp = amesa->imageline) && amesa->temprp)
  785.     {                     /* if imageline and temporary rastport have been
  786.                         allocated then use fastversion */
  787.  
  788.         ant=0;
  789.             for (i=0;i<n;i++) { /* draw pixel (x[i],y[i]) using index[i] */
  790.                 if (mask[i]) {
  791.                     ant++;
  792. //              x++;
  793.                 *dp = penconv[index[i]];
  794.                 dp++;
  795.             } else {
  796.                 if(ant)
  797.                     /* JAM: Replaced by correct call */
  798.                     /* WritePixelLine8(amesa->rp,x,y,ant,amesa->imageline,amesa->tmpras); */
  799. DEBUGOUT("awrite_index_span: WritePixelLine8()\n")
  800.                     WritePixelLine8(rp,x,y,ant,amesa->imageline,amesa->temprp);
  801.                 dp=amesa->imageline;
  802.                 ant=0;
  803.                 x++;
  804.             }
  805.         }
  806.         if(ant)
  807.             /* JAM: Replaced by correct call */
  808.             /* WritePixelLine8(amesa->rp,x,y,ant,amesa->imageline,amesa->tmpras); */
  809. DEBUGOUT("awrite_index_span: WritePixelLine8()\n")
  810.             WritePixelLine8(rp,x,y,ant,amesa->imageline,amesa->temprp);
  811.  
  812.     } else {            /* Slower */
  813.             for (i=0;i<n;i++,x++) {
  814.                 if (mask[i]) {
  815.                  /* draw pixel (x[i],y[i]) using index[i] */
  816.                 SetAPen(rp,penconv[index[i]]);
  817.                 WritePixel(rp,x,y);
  818.             }
  819.         }
  820.     }
  821. }
  822.  
  823.  
  824. static void awrite_color_span( GLcontext *ctx,GLuint n, GLint x, GLint y,
  825.                                         const GLubyte red[], const GLubyte green[],
  826.                                         const GLubyte blue[], const GLubyte alpha[],
  827.                                         const GLubyte mask[] )
  828. {
  829.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  830.     int i,ant;
  831.     UBYTE *dp;
  832.  
  833.     register struct RastPort * rp = amesa->rp;
  834.  
  835. /*DEBUGOUT("awrite_color_span(n,x,y) ")*/
  836.     
  837.     y=FIXy(y);
  838.     x=FIXx(x);
  839. /*printf("awrite_color_span(ant=%d,x=%d,y=%d)",n,x,y);*/
  840.  
  841.     if((dp = amesa->imageline) && amesa->temprp)
  842.     {           /* if imageline allocated then use fastversion */
  843. DEBUGOUT("FAST ")
  844.         if (mask)
  845.             {
  846. DEBUGOUT("mask\n")
  847.             ant=0;
  848.             for (i=0;i<n;i++)           /* draw pixel (x[i],y[i]) */
  849.                 {
  850.                 if (mask[i])
  851.                     {
  852.                     ant++;
  853.                     *dp = RGBA(amesa,red[i],green[i],blue[i],alpha[i]);
  854.                     dp++;
  855.                     }
  856.                 else
  857.                     {
  858.                     if(ant)
  859.                         {
  860.                         WritePixelLine8(rp,x,y,ant,amesa->imageline,amesa->temprp);
  861. /*printf("WritePixelLine8(ant=%d,x=%d,y=%d)\n",ant,x,y);*/
  862.                         dp=amesa->imageline;
  863.                         ant=0;
  864.                         x=x+ant;
  865.                         }
  866.                     x++;
  867.                     }
  868.                 }
  869.  
  870.             if(ant)
  871.                 {
  872.                 WritePixelLine8(rp,x,y,ant,amesa->imageline,amesa->temprp);
  873. /*printf("WritePixelLine8(ant=%d,x=%d,y=%d)\n",ant,x,y);*/
  874.                 }
  875.             }
  876.         else
  877.             {
  878. DEBUGOUT("nomask\n")
  879.             for (i=0;i<n;i++)                   /* draw pixel (x[i],y[i])*/
  880.                 {
  881.                 *dp = RGBA(amesa,red[i],green[i],blue[i],alpha[i]);
  882.                 dp++;
  883.                 }
  884.             WritePixelLine8(rp,x,y,n,amesa->imageline,amesa->temprp);
  885.             }
  886.         
  887.         }
  888.     else
  889.         {    /* Slower version */
  890. DEBUGOUT("FAST\n")
  891.         if (mask)
  892.             {
  893. DEBUGOUT("mask\n")
  894.             /* draw some pixels */
  895.             for (i=0; i<n; i++, x++)
  896.                 {
  897.                 if (mask[i])
  898.                     {
  899.                     /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  900.                     SetAPen(rp,RGBA(amesa,red[i],green[i],blue[i],alpha[i]));
  901.                     WritePixel(rp,x,y);
  902.                     }
  903.                 }
  904.             }
  905.         else
  906.             {
  907. DEBUGOUT("nomask\n")
  908.             /* draw all pixels */
  909.             for (i=0; i<n; i++, x++)
  910.                 {
  911.                 /* draw pixel x,y using color red[i]/green[i]/blue[i]/alpha[i] */
  912.                 SetAPen(rp,RGBA(amesa,red[i],green[i],blue[i],alpha[i]));
  913.                 WritePixel(rp,x,y);
  914.                 }
  915.             }
  916.         }
  917. }
  918.  
  919.  
  920.  
  921.  
  922. static void awrite_monoindex_span(GLcontext *ctx,GLuint n,GLint x,GLint y,const GLubyte mask[])
  923. {
  924.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  925.     int i;
  926.     y=FIXy(y);
  927.     x=FIXx(x);
  928.     SetAPen(amesa->rp,amesa->pixel);
  929.  
  930.  
  931. DEBUGOUT("awrite_monoindex_span\n")
  932.  
  933.  
  934.     i=0;
  935.     while(i<n)
  936.         {
  937.         while(!mask[i] && i<n)
  938.             {
  939.             i++;x++;
  940.             }
  941.  
  942.         if(i<n)
  943.             {
  944.             Move(amesa->rp,x,y);
  945.             while(mask[i] && i<n)
  946.                 {
  947.                 i++;x++;
  948.                 }
  949.             Draw(amesa->rp,x,y);
  950.             }
  951.         }
  952. }
  953.  
  954. static void awrite_monocolor_span( GLcontext *ctx,GLuint n, GLint x, GLint y,
  955.                                              const GLubyte mask[])
  956. {
  957.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  958.     int i;
  959.     register struct RastPort * rp = amesa->rp;
  960.  
  961. /*printf("awrite_monocolor_span(%d,%d,%d)\n",n,x,y);*/
  962. DEBUGOUT("awrite_monocolor_span(n,x,y)\n")
  963.  
  964.     y=FIXy(y);
  965.     x=FIXx(x);
  966.     SetAPen(rp,amesa->pixel);
  967.     i=0;
  968.     while(i<n)
  969.         {
  970.         while(!mask[i] && i<n)
  971.             {
  972.             i++;
  973.             x++;
  974.             }
  975.  
  976.         if(i<n)
  977.             {
  978.             Move(rp,x,y);
  979.             while(mask[i] && i<n)
  980.                 {
  981.                 i++;
  982.                 x++;
  983.                 }
  984.             Draw(rp,x,y);
  985.             }
  986.         }
  987. }
  988.  
  989.  
  990. /**********************************************************************/
  991. /*****                    Read spans of pixels                              *****/
  992. /**********************************************************************/
  993.  
  994. /* Here we should check if the size of the colortable is <256 */
  995.  
  996. static void aread_index_span( GLcontext *ctx,GLuint n, GLint x, GLint y, GLuint index[])
  997. {
  998.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  999.  
  1000.     int i;
  1001.  
  1002. DEBUGOUT("aread_index_span>>\n")
  1003.  
  1004.  
  1005.     y=FIXy(y);
  1006.     x=FIXx(x);
  1007.  
  1008.     if(amesa->temprp && amesa->imageline) {
  1009.         ReadPixelLine8(amesa->rp,x,y,n,amesa->imageline,amesa->temprp);
  1010.         for(i=0; i<n; i++)
  1011.             index[i]=amesa->imageline[i];
  1012.     } else {
  1013.         for (i=0; i<n; i++,x++)
  1014.             index[i] = ReadPixel(amesa->rp,x,y);
  1015.     }
  1016. }
  1017.  
  1018. static void aread_color_span( GLcontext *ctx,GLuint n, GLint x, GLint y,
  1019.                                       GLubyte red[], GLubyte green[],
  1020.                                       GLubyte blue[], GLubyte alpha[] )
  1021. {
  1022.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1023.     int i,col;
  1024.     ULONG ColTab[3];
  1025.     struct ColorMap * cm=amesa->Screen->ViewPort.ColorMap;
  1026.  
  1027. DEBUGOUT("aread_color_span>>\n")
  1028.  
  1029.  
  1030.     y=FIXy(y);
  1031.     x=FIXx(x);
  1032.  
  1033.     if(amesa->imageline && amesa->temprp) {
  1034.         ReadPixelLine8(amesa->rp,x,y,n,amesa->imageline,amesa->temprp);
  1035.         for(i=0; i<n; i++) {
  1036.             GetRGB32(cm,amesa->imageline[i],1,ColTab);
  1037.             red[i]  = ColTab[0]>>24;
  1038.             green[i] = ColTab[1]>>24;
  1039.             blue[i] = ColTab[2]>>24;
  1040.             alpha[i]=255;
  1041.         }
  1042.     } else
  1043.         for (i=0; i<n; i++, x++) {
  1044.             col=ReadPixel(amesa->rp,x,y);
  1045.             GetRGB32(cm,col,1,ColTab);
  1046.  
  1047.             red[i]  = ColTab[0]>>24;
  1048.             green[i] = ColTab[1]>>24;
  1049.             blue[i] = ColTab[2]>>24;
  1050.             alpha[i]=255;
  1051.             }
  1052. }
  1053.  
  1054.  
  1055.  
  1056.  
  1057. /**********************************************************************/
  1058. /*****                Write arrays of pixels                                *****/
  1059. /**********************************************************************/
  1060.  
  1061. static void awrite_index_pixels_db( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  1062.                                           const GLuint index[], const GLubyte mask[] )
  1063. {
  1064.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1065.  
  1066.     int i;
  1067. //  register struct RastPort * rp = amesa->rp;
  1068. DEBUGOUT("awrite_index_pixels<\n")
  1069.  
  1070.     for (i=0; i<n; i++)
  1071.         {
  1072.         if (mask[i])
  1073.             {
  1074.             amesa->BackArray[FIXxy(x[i],y[i])]=amesa->penconv[index[i]];
  1075.             }
  1076.         }
  1077. }
  1078.  
  1079. static void awrite_monoindex_pixels_db( GLcontext *ctx,GLuint n,
  1080.                                                 const GLint x[], const GLint y[],
  1081.                                                 const GLubyte mask[] )
  1082. {
  1083.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1084.     int i;
  1085. //  register struct RastPort * rp = amesa->rp;
  1086. DEBUGOUT("awrite_index_pixels<\n")
  1087.  
  1088.     for (i=0; i<n; i++)
  1089.         {
  1090.         if (mask[i])
  1091.             {
  1092.             amesa->BackArray[FIXxy(x[i],y[i])]=amesa->pixel;
  1093.             }
  1094.         }
  1095. }
  1096.  
  1097. static void awrite_color_pixels_db(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
  1098.                                               const GLubyte r[], const GLubyte g[],
  1099.                                               const GLubyte b[], const GLubyte a[],
  1100.                                               const GLubyte mask[] )
  1101. {
  1102.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1103.     int i;
  1104. //  register struct RastPort * rp = amesa->rp;
  1105. DEBUGOUT("awrite_index_pixels<\n")
  1106.  
  1107.     for (i=0; i<n; i++)
  1108.         {
  1109.         if (mask[i])
  1110.             {
  1111.             amesa->BackArray[FIXxy(x[i],y[i])]=RGBA(amesa,r[i],g[i],b[i],a[i]);
  1112.             }
  1113.         }
  1114. }
  1115.  
  1116.  
  1117. static void awrite_index_pixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[],
  1118.                                           const GLuint index[], const GLubyte mask[] )
  1119. {
  1120.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1121.     int i;
  1122.     register struct RastPort * rp = amesa->rp;
  1123. DEBUGOUT("awrite_index_pixels<\n")
  1124.  
  1125.     for (i=0; i<n; i++)
  1126.         {
  1127.         if (mask[i])
  1128.             {
  1129.             SetAPen(rp,amesa->penconv[index[i]]);
  1130.             WritePixel(rp,FIXx(x[i]),FIXy(y[i]));
  1131.             }
  1132.         }
  1133. }
  1134.  
  1135.  
  1136. static void awrite_monoindex_pixels(GLcontext *ctx, GLuint n,
  1137.                                                 const GLint x[], const GLint y[],
  1138.                                                 const GLubyte mask[] )
  1139. {
  1140.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1141.     int i;
  1142.     register struct RastPort * rp = amesa->rp;
  1143.  
  1144. DEBUGOUT("awrite_monoindex_pixels<\n");
  1145.  
  1146.         SetAPen(rp,amesa->pixel);
  1147.  
  1148.     for (i=0; i<n; i++) {
  1149.         if (mask[i]) {
  1150. /*        write pixel x[i], y[i] using current index  */
  1151.         WritePixel(rp,FIXx(x[i]),FIXy(y[i]));
  1152.  
  1153.         }
  1154.     }
  1155. }
  1156.  
  1157.  
  1158.  
  1159. static void awrite_color_pixels( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  1160.                                           const GLubyte r[], const GLubyte g[],
  1161.                                           const GLubyte b[], const GLubyte a[],
  1162.                                           const GLubyte mask[] )
  1163. {
  1164.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1165.     int i;
  1166.     register struct RastPort * rp = amesa->rp;
  1167.  
  1168. DEBUGOUT("awrite_color_pixels<\n")
  1169.  
  1170.     for (i=0; i<n; i++) {
  1171.         if (mask[i]) {
  1172. /*        write pixel x[i], y[i] using red[i],green[i],blue[i],alpha[i] */
  1173.         SetAPen(rp,RGBA(amesa,r[i],g[i],b[i],a[i]));
  1174.         WritePixel(rp,FIXx(x[i]),FIXy(y[i]));
  1175.         }
  1176.     }
  1177. }
  1178.  
  1179.  
  1180.  
  1181. static void awrite_monocolor_pixels(GLcontext *ctx, GLuint n,
  1182.                                                 const GLint x[], const GLint y[],
  1183.                                                 const GLubyte mask[] )
  1184. {
  1185.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1186.     int i;
  1187.     register struct RastPort * rp = amesa->rp;
  1188.  
  1189. DEBUGOUT("awrite_monocolor_pixels<\n")
  1190.  
  1191.         SetAPen(rp,amesa->pixel);
  1192.  
  1193.     for (i=0; i<n; i++) {
  1194.         if (mask[i]) {
  1195. /*        write pixel x[i], y[i] using current color*/
  1196.         WritePixel(rp,FIXx(x[i]),FIXy(y[i]));
  1197.         }
  1198.     }
  1199. }
  1200.  
  1201.  
  1202.  
  1203.  
  1204. /**********************************************************************/
  1205. /*****                       Read arrays of pixels                          *****/
  1206. /**********************************************************************/
  1207.  
  1208. /* Read an array of color index pixels. */
  1209. static void aread_index_pixels( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  1210.                                          GLuint index[], const GLubyte mask[] )
  1211. {
  1212.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1213.     int i;
  1214.     register struct RastPort * rp = amesa->rp;
  1215.  
  1216. DEBUGOUT("aread_index_pixels-\n")
  1217.     
  1218.  
  1219.   for (i=0; i<n; i++) {
  1220.       if (mask[i]) {
  1221. /*       index[i] = read_pixel x[i], y[i] */
  1222.         index[i] = ReadPixel(rp,FIXx(x[i]),FIXy(y[i]));
  1223.       }
  1224.   }
  1225. }
  1226.  
  1227. static void aread_color_pixels( GLcontext *ctx,GLuint n, const GLint x[], const GLint y[],
  1228.                                          GLubyte red[], GLubyte green[],
  1229.                                          GLubyte blue[], GLubyte alpha[],
  1230.                                          const GLubyte mask[] )
  1231. {
  1232.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1233.     int i,col;
  1234.     register struct RastPort * rp = amesa->rp;
  1235.  
  1236.     ULONG ColTab[3];
  1237.  
  1238. DEBUGOUT("aread_color_pixels-\n")
  1239.         
  1240.  
  1241.     for (i=0; i<n; i++)
  1242.         {
  1243.         if (mask[i])
  1244.             {
  1245.             col=ReadPixel(rp,FIXx(x[i]),FIXy(y[i]));
  1246.  
  1247.             GetRGB32(amesa->Screen->ViewPort.ColorMap,col,1,ColTab);
  1248.  
  1249.             red[i]  = ColTab[0]>>24;
  1250.             green[i] = ColTab[1]>>24;
  1251.             blue[i] = ColTab[2]>>24;
  1252.             alpha[i]=255;
  1253.         }
  1254.     }
  1255. }
  1256.  
  1257.  
  1258.  
  1259. static GLboolean aset_buffer( GLcontext *ctx,GLenum mode )
  1260. {
  1261.     /* set the current drawing/reading buffer, return GL_TRUE or GL_FALSE */
  1262.     /* for success/failure */
  1263.     
  1264. /*   AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx; */
  1265.  
  1266.  
  1267. /* amiga_setup_DD_pointers(); in ddsample is this right?????*/
  1268. DEBUGOUT("aset_buffer TODO\n")
  1269.     
  1270.  
  1271. /* TODO implemed a set of buffers */
  1272.     if (mode==GL_FRONT)
  1273.         {
  1274.         return(GL_TRUE);
  1275.         }
  1276.     else if (mode==GL_BACK)
  1277.         {
  1278.         return(GL_TRUE);
  1279.         }
  1280.     else
  1281.         {
  1282.         return(GL_FALSE);
  1283.         }
  1284. }
  1285.  
  1286.  
  1287.  
  1288.  
  1289. /**********************************************************************/
  1290. /**********************************************************************/
  1291.     /* Initialize all the pointers in the DD struct.  Do this whenever   */
  1292.     /* a new context is made current or we change buffers via set_buffer! */
  1293. void amiga_standard_DD_pointers( GLcontext *ctx )
  1294. {
  1295. //   AmigaMesaContext amesa = ctx->DriverCtx;
  1296.  
  1297. DEBUGOUT("Inside amiga_standard_DD_pointers\n")
  1298. #ifdef DEBUGPRINT
  1299. printf("ctx=0x%x\n",ctx);
  1300. printf("CC=0x%x\n",CC);
  1301. #endif
  1302.  
  1303. //  ctx=CC;  /* BRUTE FORCE OVERERIDE REMOVE PLEASE */
  1304.  
  1305.  
  1306.    ctx->Driver.UpdateState = amiga_standard_DD_pointers;
  1307.    ctx->Driver.ClearIndex = aclear_index;
  1308.    ctx->Driver.ClearColor = aclear_color;
  1309.    ctx->Driver.Clear = aclear;
  1310.  
  1311.    ctx->Driver.Index = aset_index;
  1312.    ctx->Driver.Color = aset_color;
  1313.  
  1314.    ctx->Driver.IndexMask = aindex_mask;
  1315.    ctx->Driver.ColorMask = acolor_mask;
  1316.  
  1317.    ctx->Driver.SetBuffer = aset_buffer;
  1318.    ctx->Driver.GetBufferSize = Amiga_Standard_resize;
  1319.  
  1320.    ctx->Driver.PointsFunc = achoose_points_function( ctx );
  1321.    ctx->Driver.LineFunc = achoose_line_function( ctx );
  1322. //   ctx->Driver.PolygonFunc = achoose_polygon_function( ctx );
  1323.     ctx->Driver.TriangleFunc = FALSE;  //TODO
  1324.  
  1325.    /* Pixel/span writing functions: */
  1326.    ctx->Driver.WriteColorSpan       = awrite_color_span;
  1327.    ctx->Driver.WriteMonocolorSpan   = awrite_monocolor_span;
  1328.    ctx->Driver.WriteColorPixels     = awrite_color_pixels;
  1329.    ctx->Driver.WriteMonocolorPixels = awrite_monocolor_pixels;
  1330.    ctx->Driver.WriteIndexSpan       = awrite_index_span;
  1331.    ctx->Driver.WriteMonoindexSpan   = awrite_monoindex_span;
  1332.    ctx->Driver.WriteIndexPixels     = awrite_index_pixels;
  1333.    ctx->Driver.WriteMonoindexPixels = awrite_monoindex_pixels;
  1334.  
  1335.    /* Pixel/span reading functions: */
  1336.    ctx->Driver.ReadIndexSpan = aread_index_span;
  1337.    ctx->Driver.ReadColorSpan = aread_color_span;
  1338.    ctx->Driver.ReadIndexPixels = aread_index_pixels;
  1339.    ctx->Driver.ReadColorPixels = aread_color_pixels;
  1340. }
  1341.  
  1342. void amiga_Faster_DD_pointers( GLcontext *ctx )
  1343. {
  1344. //   AmigaMesaContext amesa = ctx->DriverCtx;
  1345.  
  1346.     ctx=CC;  /* BRUTE FORCE OVERERIDE REMOVE PLEASE */
  1347.  
  1348.    ctx->Driver.UpdateState = amiga_Faster_DD_pointers;
  1349.    ctx->Driver.ClearIndex = aclear_index;
  1350.    ctx->Driver.ClearColor = aclear_color;
  1351.    ctx->Driver.Clear = aclear_db;
  1352.  
  1353.    ctx->Driver.Index = aset_index;
  1354.    ctx->Driver.Color = aset_color;
  1355.  
  1356.    ctx->Driver.IndexMask = aindex_mask;
  1357.    ctx->Driver.ColorMask = acolor_mask;
  1358.  
  1359.    ctx->Driver.SetBuffer = aset_buffer;
  1360.    ctx->Driver.GetBufferSize = Amiga_Standard_resize_db;
  1361.  
  1362.    ctx->Driver.PointsFunc = achoose_points_function_db( ctx );
  1363.    ctx->Driver.LineFunc = achoose_line_function_db( ctx );
  1364. //   ctx->Driver.PolygonFunc = achoose_polygon_function_db( ctx );
  1365.     ctx->Driver.TriangleFunc = FALSE;  //TODO
  1366.  
  1367.    /* Pixel/span writing functions: */
  1368.    ctx->Driver.WriteColorSpan       = awrite_color_span_db;
  1369.    ctx->Driver.WriteMonocolorSpan   = awrite_monoindex_span_db; /* same */
  1370.    ctx->Driver.WriteColorPixels     = awrite_color_pixels_db;
  1371.    ctx->Driver.WriteMonocolorPixels = awrite_monoindex_pixels_db;   /* same */
  1372.    ctx->Driver.WriteIndexSpan       = awrite_index_span_db;
  1373.    ctx->Driver.WriteMonoindexSpan   = awrite_monoindex_span_db;
  1374.    ctx->Driver.WriteIndexPixels     = awrite_index_pixels_db;
  1375.    ctx->Driver.WriteMonoindexPixels = awrite_monoindex_pixels_db;
  1376.  
  1377.    /* Pixel/span reading functions: */
  1378.    ctx->Driver.ReadIndexSpan = aread_index_span;
  1379.    ctx->Driver.ReadColorSpan = aread_color_span;
  1380.    ctx->Driver.ReadIndexPixels = aread_index_pixels;
  1381.    ctx->Driver.ReadColorPixels = aread_color_pixels;
  1382. }
  1383. /**********************************************************************/
  1384. /*****                  Amiga/Mesa Private Functions                        *****/
  1385. /**********************************************************************/
  1386. /* JAM: temporary rastport allocation and freeing */
  1387.  
  1388. BOOL alloc_temp_rastport(struct amigamesa_context * c) {
  1389.     struct RastPort * temprp;
  1390.  
  1391. DEBUGOUT("alloc_temp_rastport()\n")
  1392.     if(temprp= AllocVec(sizeof(struct RastPort), 0)) {
  1393.         CopyMem(c->rp, temprp, sizeof(struct RastPort));
  1394.         temprp->Layer = NULL;
  1395.  
  1396.         if(temprp->BitMap= AllocBitMap(c->FixedWidth, 1,
  1397.                                          c->rp->BitMap->Depth,0,c->rp->BitMap)) {
  1398. //temprp->BytesPerRow == (((width+15)>>4)<<1)
  1399.             c->temprp=temprp;
  1400.             return TRUE;
  1401.         }
  1402.         FreeVec(temprp);
  1403.     }
  1404.     printf("Error allocating temporary rastport");
  1405.     return FALSE;
  1406. }
  1407.  
  1408.  void free_temp_rastport(struct amigamesa_context * c) {
  1409. DEBUGOUT("free_temp_rastport\n")
  1410.     if(c->temprp) {
  1411.         FreeBitMap(c->temprp->BitMap);
  1412.         FreeVec(c->temprp);
  1413.     }
  1414.     c->temprp=NULL;
  1415. }
  1416.  
  1417. /*
  1418.  * Create a new rastport to use as a back buffer.
  1419.  * Input:  width, height - size in pixels
  1420.  *        depth - number of bitplanes
  1421.  */
  1422.  
  1423. struct RastPort *make_rastport( int width, int height, int depth, struct BitMap *friendbm )
  1424.     {
  1425.     struct RastPort *rp;
  1426.     struct BitMap *bm;
  1427.  
  1428.     if (bm=AllocBitMap(width,height,depth,BMF_CLEAR|BMF_INTERLEAVED,friendbm))
  1429.         {
  1430.         if (rp = (struct RastPort *) malloc( sizeof(struct RastPort)))
  1431.             {
  1432.             InitRastPort( rp );
  1433.             rp->BitMap = bm;
  1434.             return rp;
  1435.             }
  1436.         else
  1437.             {
  1438.             FreeBitMap(bm);
  1439.             return 0;
  1440.             }
  1441.         }
  1442.     else
  1443.         return 0;
  1444. }
  1445.  
  1446.  
  1447. /*
  1448.  * Deallocate a rastport.
  1449.  */
  1450.  
  1451. void destroy_rastport( struct RastPort *rp )
  1452.     {
  1453.     WaitBlit();
  1454.     FreeBitMap( rp->BitMap );
  1455.     free( rp );
  1456.     }
  1457.  
  1458.     /* 
  1459.     ** Color_buf is a array of pens equals the drawing area
  1460.     ** it's for faster dubbelbuffer rendering
  1461.     ** Whent it's time for bufferswitch just use c2p and copy.
  1462.     */
  1463.  
  1464. UBYTE* alloc_penbackarray( int width, int height, int bytes)
  1465.     {
  1466.     return(AllocVec(width*height*bytes, MEMF_PUBLIC|MEMF_CLEAR));
  1467.     }
  1468.  
  1469. void destroy_penbackarray(UBYTE *buf)
  1470.     {
  1471.     FreeVec(buf);
  1472.     }
  1473.  
  1474.  
  1475.  
  1476. /*
  1477.  * Construct a temporary raster for use by the given rasterport.
  1478.  * Temp rasters are used for polygon drawing.
  1479.  */
  1480.  
  1481. BOOL make_temp_raster( struct RastPort *rp ) {
  1482.     BOOL    OK=TRUE;
  1483.     unsigned long width, height;
  1484.     PLANEPTR p;
  1485.     struct TmpRas *tmpras;
  1486.  
  1487.     if(rp==0) {
  1488.         printf("Zero rp\n");
  1489.         return(FALSE);
  1490.     }
  1491.         width = rp->BitMap->BytesPerRow*8;
  1492.         height = rp->BitMap->Rows;
  1493.  
  1494.     /* allocate structures */
  1495.         if(p = AllocRaster( width, height )) {
  1496.             if(tmpras = (struct TmpRas *) AllocVec( sizeof(struct TmpRas),
  1497.                                                     MEMF_ANY)) {
  1498.             if(InitTmpRas( tmpras, p, ((width+15)>>4)*height )) {
  1499.                 rp->TmpRas = tmpras;
  1500.             } else
  1501.                     OK=FALSE;
  1502.             } else
  1503.             OK=FALSE;
  1504.     } else
  1505.         return(FALSE);
  1506.  
  1507.     if (OK)
  1508.         return(TRUE);
  1509.     else {
  1510.         printf("Error when allocationg TmpRas\n");
  1511.         if (tmpras)
  1512.             FreeVec(tmpras);
  1513.         if (p)
  1514.             FreeRaster(p,width, height);
  1515.         return(FALSE);
  1516.         }
  1517. }
  1518.  
  1519. static BOOL allocarea(struct RastPort *rp ) {
  1520.     BOOL    OK=TRUE;
  1521.     struct AreaInfo *areainfo;
  1522.     UWORD *pattern;
  1523.     APTR vbuffer;
  1524.  
  1525.     areainfo = (struct AreaInfo *) AllocVec( sizeof(struct AreaInfo),MEMF_ANY );
  1526.     if(areainfo!=0) {
  1527.         pattern = (UWORD *) AllocVec( sizeof(UWORD),MEMF_ANY);
  1528.         if(pattern!=0) {
  1529.             *pattern = 0xffff;      /*@@@ org: 0xffffffff*/
  1530.             vbuffer = (APTR) AllocVec( MAX_POLYGON * 5 * sizeof(WORD),MEMF_ANY);
  1531.             if(vbuffer!=0) {
  1532.                 /* initialize */
  1533.                 InitArea( areainfo, vbuffer, MAX_POLYGON );
  1534.                 /* bind to rastport */
  1535.                 rp->AreaPtrn = pattern;
  1536.                 rp->AreaInfo = areainfo;
  1537.                 rp->AreaPtSz = 0;
  1538.             } else
  1539.                 OK=FALSE;
  1540.         } else
  1541.                 OK=FALSE;
  1542.     } else
  1543.             OK=FALSE;
  1544.  
  1545.     if (OK)
  1546.         return (OK);
  1547.     else {
  1548.         printf("Error when allocationg AreaBuffers\n");
  1549.         if (vbuffer)
  1550.             FreeVec(vbuffer);
  1551.         if (pattern)
  1552.             FreeVec(pattern);
  1553.         if (areainfo)
  1554.             FreeVec(areainfo);
  1555.         return(OK);
  1556.         }
  1557. }
  1558.  
  1559. void freearea(struct RastPort *rp) {
  1560.     if (rp->AreaInfo) {
  1561.         if (rp->AreaInfo->VctrTbl)
  1562.             FreeVec(rp->AreaInfo->VctrTbl);
  1563.         if (rp->AreaPtrn) {
  1564.             FreeVec(rp->AreaPtrn);
  1565.             rp->AreaPtrn=NULL;
  1566.         }
  1567.         FreeVec(rp->AreaInfo);
  1568.         rp->AreaInfo=NULL;
  1569.     }
  1570. }
  1571.  
  1572. /*
  1573.  * Destroy a temp raster.
  1574.  */
  1575.  
  1576.  
  1577. void destroy_temp_raster( struct RastPort *rp )
  1578.     {
  1579.     /* bitmap */
  1580.  
  1581.     unsigned long width, height;
  1582.  
  1583.     width = rp->BitMap->BytesPerRow*8;
  1584.     height = rp->BitMap->Rows;
  1585.  
  1586.     if (rp->TmpRas)
  1587.         {
  1588.         if(rp->TmpRas->RasPtr)
  1589.             FreeRaster( rp->TmpRas->RasPtr,width,height );
  1590.         FreeVec( rp->TmpRas );
  1591.         rp->TmpRas=NULL;
  1592.  
  1593.         }
  1594. }
  1595.  
  1596.  
  1597. void AllocOneLine( struct amigamesa_context *c) {
  1598.     if(c->imageline)
  1599.         FreeVec(c->imageline);
  1600.     if (c->depth<=8) {
  1601.         c->imageline = AllocVec((c->width+15) & 0xfffffff0,MEMF_ANY);   /* One Line */
  1602.     } else {
  1603.         c->imageline = AllocVec(((c->width+3) & 0xfffffff0)*4,MEMF_ANY);   /* One Line */
  1604.     }
  1605. }
  1606.  
  1607. void FreeOneLine( struct amigamesa_context *c) {
  1608.     if(c->imageline) {
  1609.         FreeVec(c->imageline);
  1610.         c->imageline=NULL;
  1611.     }
  1612. }
  1613. /**********************************************************************/
  1614. /*****                  Amiga/Mesa private init/despose/resize       *****/
  1615. /**********************************************************************/
  1616.  
  1617. static void
  1618. Amiga_Standard_resize( GLcontext *ctx,GLuint *width, GLuint *height)
  1619.     {
  1620.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1621.  
  1622. DEBUGOUT("Amiga_Standard_resize\n")
  1623.     *width=amesa->width;
  1624.     *height=amesa->height;
  1625.     
  1626.     if(!((  amesa->width  == (amesa->front_rp->Layer->bounds.MaxX-amesa->front_rp->Layer->bounds.MinX-amesa->left) ) 
  1627.     &&  ( amesa->height == (amesa->front_rp->Layer->bounds.MaxY-amesa->front_rp->Layer->bounds.MinY-amesa->bottom)  )))
  1628.         {
  1629.         FreeOneLine(amesa);
  1630.  
  1631.         amesa->FixedWidth =amesa->RealWidth =amesa->front_rp->Layer->bounds.MaxX-amesa->front_rp->Layer->bounds.MinX;
  1632.         amesa->FixedHeight=amesa->RealHeight=amesa->front_rp->Layer->bounds.MaxY-amesa->front_rp->Layer->bounds.MinY;
  1633.  
  1634.         *width=amesa->width = amesa->RealWidth-amesa->left;
  1635.         *height=amesa->height = amesa->RealHeight-amesa->bottom;
  1636.         amesa->depth = GetBitMapAttr(amesa->front_rp->BitMap,BMA_DEPTH);
  1637.  
  1638.         destroy_temp_raster( amesa->rp); /* deallocate temp raster */
  1639.  
  1640.         /* JAM: Added free_temp_rastport() */
  1641.         free_temp_rastport(amesa);
  1642.  
  1643.         if (amesa->visual->db_flag) {
  1644.             if (amesa->back_rp) {   /* Free double buffer */
  1645.                 destroy_rastport(amesa->back_rp);
  1646.             }
  1647.             if((amesa->back_rp = make_rastport(amesa->RealWidth,amesa->RealHeight,amesa->depth,amesa->rp->BitMap))==NULL) {
  1648.                 amesa->rp = amesa->front_rp;
  1649.                 printf("To little mem free. Couldn't allocate Dubblebuffer in this size.\n");
  1650.             } else {
  1651.                 amesa->rp=amesa->back_rp;
  1652.             }
  1653.         }
  1654.  
  1655.         if(!make_temp_raster( amesa->rp ))
  1656.             printf("Error allocating TmpRasterPort\n");
  1657.  
  1658.         /* JAM: added alloc_temp_rastport */
  1659.         alloc_temp_rastport(amesa);
  1660.  
  1661.     
  1662.         AllocOneLine(amesa);
  1663.         }
  1664.     }
  1665.  
  1666. void
  1667. Amiga_Standard_Dispose(struct amigamesa_context *c)
  1668.     {
  1669. DEBUGOUT("Amiga_Standard_Dispose\n")
  1670.     FreeOneLine(c);
  1671.     if (c->depth<=8) {
  1672.         FreeCMap(c->Screen);
  1673.         freearea(c->rp);
  1674.         destroy_temp_raster( c->rp);
  1675.         /* JAM: Added free_temp_rastport() */
  1676.         free_temp_rastport(c);
  1677.     }
  1678.  
  1679.     if (c->visual->rgb_flag)
  1680.         {
  1681.         if (c->rgb_buffer)
  1682.             {
  1683.             printf("free(c->rgb_buffer)\n");
  1684.             free( c->rgb_buffer );
  1685.             }
  1686.         }
  1687.  
  1688.     if (c->back_rp)
  1689.         {
  1690.         destroy_rastport( c->back_rp );
  1691.         c->back_rp=NULL;
  1692.         }
  1693.     }
  1694.  
  1695. void
  1696. Amiga_Standard_SwapBuffer(struct amigamesa_context *amesa)
  1697. {
  1698. DEBUGOUT("Amiga_Standard_SwapBuffer\n")
  1699.  
  1700.         if (amesa->back_rp)
  1701.             {
  1702.             UBYTE minterm = 0xc0;
  1703. //          int x = amesa->left;
  1704. //          int y = amesa->RealHeight-amesa->bottom-amesa->height;
  1705.         
  1706.             ClipBlit( amesa->back_rp, FIXx(amesa->gl_ctx->Viewport.X), FIXy(amesa->gl_ctx->Viewport.Y)-amesa->gl_ctx->Viewport.Height+1,    /* from */
  1707.                          amesa->front_rp, FIXx(amesa->gl_ctx->Viewport.X), FIXy(amesa->gl_ctx->Viewport.Y)-amesa->gl_ctx->Viewport.Height+1,  /* to */
  1708.                          amesa->gl_ctx->Viewport.Width, amesa->gl_ctx->Viewport.Height,  /* size */
  1709.                          minterm );
  1710. /*          ClipBlit( amesa->back_rp, x, y, *//* from *//*
  1711.                          amesa->front_rp, x,y,  *//* to *//*
  1712.                          amesa->width, amesa->height,  *//* size *//*
  1713.                          minterm );
  1714. */
  1715.     /* TODO Use these cordinates insted more efficent if you only use part of screen
  1716.             RectFill(amesa->rp,FIXx(CC.Viewport.X),FIXy(CC.Viewport.Y)-CC.Viewport.Height+1,FIXx(CC.Viewport.X)+CC.Viewport.Width-1,FIXy(CC.Viewport.Y));*/
  1717.             }
  1718. }
  1719.  
  1720.  
  1721. static void
  1722. Amiga_Standard_resize_db( GLcontext *ctx,GLuint *width, GLuint *height)
  1723.     {
  1724.    AmigaMesaContext amesa = (AmigaMesaContext) ctx->DriverCtx;
  1725.  
  1726. DEBUGOUT("Amiga_Standard_resize_db\n")
  1727.  
  1728.     *width=amesa->width;
  1729.     *height=amesa->height;
  1730.     
  1731.     if(!((  amesa->width  == (amesa->rp->Layer->bounds.MaxX-amesa->rp->Layer->bounds.MinX-amesa->left) ) 
  1732.     &&  ( amesa->height == (amesa->rp->Layer->bounds.MaxY-amesa->rp->Layer->bounds.MinY-amesa->bottom)  )))
  1733.         {
  1734.         /* JAM: Added free_temp_rastport() */
  1735.         free_temp_rastport(amesa);
  1736.  
  1737.         amesa->RealWidth =amesa->rp->Layer->bounds.MaxX-amesa->rp->Layer->bounds.MinX;
  1738.         amesa->RealHeight=amesa->rp->Layer->bounds.MaxY-amesa->rp->Layer->bounds.MinY;
  1739.         amesa->FixedWidth =((amesa->RealWidth+15)>>4)<<4;
  1740.         amesa->FixedHeight=amesa->RealHeight+1;
  1741.  
  1742.  
  1743.         *width=amesa->width = amesa->RealWidth-amesa->left;
  1744.         *height=amesa->height = amesa->RealHeight-amesa->bottom;
  1745. //      amesa->left = 0;
  1746. //      amesa->bottom = 0;
  1747.         amesa->depth = GetBitMapAttr(amesa->rp->BitMap,BMA_DEPTH);
  1748.  
  1749.         if (amesa->visual->db_flag && amesa->BackArray)
  1750.             {
  1751.             destroy_penbackarray(amesa->BackArray);
  1752.             if(!(amesa->BackArray=alloc_penbackarray(amesa->RealWidth,amesa->RealHeight,amesa->depth<=8 ? 1 : 4)))
  1753.                 {
  1754.                 printf("AmigaMesa Error Can't allocate new PenArray in that size.\n");
  1755. //              Amiga_Standard_init(amesa);
  1756.  
  1757.                 }
  1758.             }
  1759.  
  1760.         /* JAM: added alloc_temp_rastport */
  1761.         alloc_temp_rastport(amesa);
  1762. #ifdef DEBUGPRINT
  1763.     printf("amesa->RealWidth =%d\n",amesa->RealWidth);
  1764.     printf("amesa->RealHeight=%d\n",amesa->RealHeight);
  1765.     printf("amesa->width =%d\n",amesa->width);
  1766.     printf("amesa->height=%d\n",amesa->height);
  1767.     printf("amesa->left  =%d\n",amesa->left);
  1768.     printf("amesa->bottom=%d\n",amesa->bottom);
  1769.     printf("amesa->depth =%d\n",amesa->depth);
  1770. #endif
  1771.  
  1772.         }
  1773.     }
  1774.  
  1775.  
  1776.  
  1777. void
  1778. Amiga_Standard_Dispose_db(struct amigamesa_context *c)
  1779.     {
  1780. DEBUGOUT("Amiga_Standard_Dispose_db\n")
  1781. //  printf("I'm closing down\n");getchar();
  1782.     if (c->depth<=8) {
  1783.         FreeCMap(c->Screen);
  1784.  
  1785.   /*    JAM: Added free_temp_rastport()*/
  1786.         free_temp_rastport(c);
  1787.     }
  1788.  
  1789.     if (c->BackArray)
  1790.         {
  1791.         destroy_penbackarray(c->BackArray);
  1792.         }
  1793.     }
  1794.  
  1795. static void
  1796. Amiga_Standard_SwapBuffer_db(struct amigamesa_context *amesa)
  1797. {
  1798. DEBUGOUT("Amiga_Standard_SwapBuffer_db\n")
  1799.  
  1800. //        WriteChunkyPixels(amesa->rp,amesa->left,amesa->RealHeight-amesa->height,amesa->RealWidth,amesa->RealHeight-amesa->bottom,amesa->BackArray,amesa->RealWidth);
  1801.  
  1802.         WritePixelArray8(amesa->rp,amesa->left+amesa->gl_ctx->Viewport.X,
  1803.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1804.                                      amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width,
  1805.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y,
  1806.                                      amesa->BackArray,
  1807.                                      amesa->temprp);
  1808. /*        printf("WritePixelArray8(%d,%d,%d,%d);\n",
  1809.                                               amesa->left+amesa->gl_ctx->Viewport.X,
  1810.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Height-amesa->gl_ctx->Viewport.Y,
  1811.                                      amesa->left+amesa->gl_ctx->Viewport.X+amesa->gl_ctx->Viewport.Width,
  1812.                                      amesa->RealHeight-amesa->bottom-amesa->gl_ctx->Viewport.Y);
  1813. */
  1814.  
  1815. }
  1816.  
  1817.  
  1818.  
  1819.  
  1820. BOOL
  1821. Amiga_Standard_init_db(struct amigamesa_context *c,struct TagItem *tagList)
  1822.     {
  1823. DEBUGOUT("Amiga_Standard_init_db\n")
  1824.     c->window=(struct Window *)GetTagData(AMA_Window,0,tagList);
  1825.     if (!c->window)
  1826.         {
  1827.         c->rp=(struct RastPort *)GetTagData(AMA_RastPort,0,tagList);
  1828.         if (!c->rp)
  1829.             {
  1830.             LastError=AMESA_RASTPORT_TAG_MISSING;
  1831.             return(FALSE);
  1832.             }
  1833.         c->Screen=(struct Screen *)GetTagData(AMA_Screen,0,tagList);
  1834.         if (!c->Screen)
  1835.             {
  1836.             LastError=AMESA_SCREEN_TAG_MISSING;
  1837.             return(FALSE);
  1838.             }
  1839.         }
  1840.     else
  1841.         {
  1842.         c->rp =c->window->RPort;
  1843.         c->Screen=c->window->WScreen;
  1844.         }
  1845.  
  1846.     c->RealWidth =c->rp->Layer->bounds.MaxX-c->rp->Layer->bounds.MinX;
  1847.     c->RealHeight=c->rp->Layer->bounds.MaxY-c->rp->Layer->bounds.MinY;
  1848.     c->FixedWidth =((c->RealWidth+15)>>4)<<4;
  1849.     c->FixedHeight=c->RealHeight+1;
  1850.  
  1851.  
  1852.     c->left = GetTagData(AMA_Left,0,tagList);
  1853.     c->bottom = GetTagData(AMA_Bottom,0,tagList);
  1854.  
  1855.     c->width = GetTagData(AMA_Width,c->RealWidth-c->left,tagList);
  1856.     c->height= GetTagData(AMA_Height,c->RealHeight-c->bottom,tagList);
  1857.  
  1858.     c->depth = GetBitMapAttr(c->rp->BitMap,BMA_DEPTH);
  1859. /*
  1860.     c->gl_ctx->BufferWidth = c->width;
  1861.     c->gl_ctx->BufferHeight = c->height;
  1862. */
  1863. //    c->pixel = 0;    /* current drawing pen */
  1864.  
  1865.     AllocCMap(c->Screen);    /* colormap */
  1866.     /* JAM: added alloc_temp_rastport */
  1867.     alloc_temp_rastport(c);
  1868.  
  1869.  
  1870.     if (c->visual->db_flag)
  1871.         {
  1872.         c->BackArray=alloc_penbackarray(c->FixedWidth,c->FixedHeight,c->depth<=8 ? 1 : 4);
  1873. #ifdef DEBUGPRINT
  1874. printf("byte array at -------->0x%x ends at 0x%x size=0x%x (%d)\n",c->BackArray,c->BackArray+(((c->RealWidth+15)>>4)<<4)*(c->RealHeight+1),(((c->RealWidth+15)>>4)<<4)*(c->RealHeight+1),(((c->RealWidth+15)>>4)<<4)*(c->RealHeight+1));
  1875. #endif
  1876.         c->gl_ctx->Color.DrawBuffer = GL_BACK;
  1877.  
  1878.         c->InitDD=amiga_Faster_DD_pointers;  /*fast drawing*/
  1879.         c->Dispose=Amiga_Standard_Dispose_db;
  1880.         c->SwapBuffer=Amiga_Standard_SwapBuffer_db;
  1881.         }
  1882.     else
  1883.         {
  1884.         c->gl_ctx->Color.DrawBuffer = GL_FRONT;
  1885.         return(FALSE);
  1886.         }
  1887. #ifdef DEBUGPRINT
  1888.     printf("c->RealWidth =%d\n",c->RealWidth);
  1889.     printf("c->RealHeight=%d\n",c->RealHeight);
  1890.     printf("c->width =%d\n",c->width);
  1891.     printf("c->height=%d\n",c->height);
  1892.     printf("c->left  =%d\n",c->left);
  1893.     printf("c->bottom=%d\n",c->bottom);
  1894.     printf("c->depth =%d\n",c->depth);
  1895. #endif
  1896.     return(TRUE);
  1897.     }
  1898.  
  1899.  
  1900. BOOL
  1901. Amiga_Standard_init(struct amigamesa_context *c,struct TagItem *tagList)
  1902.     {
  1903. DEBUGOUT("Amiga_Standard_init\n")
  1904.     c->window=(struct Window *)GetTagData(AMA_Window,0,tagList);
  1905.     if (!c->window)
  1906.         {
  1907.         c->rp=(struct RastPort *)GetTagData(AMA_RastPort,0,tagList);
  1908.         if (!c->rp)
  1909.             {
  1910.             LastError=AMESA_RASTPORT_TAG_MISSING;
  1911.             return(FALSE);
  1912.             }
  1913.         c->Screen=(struct Screen *)GetTagData(AMA_Screen,0,tagList);
  1914.         if (!c->Screen)
  1915.             {
  1916.             LastError=AMESA_SCREEN_TAG_MISSING;
  1917.             return(FALSE);
  1918.             }
  1919.         }
  1920.     else
  1921.         {
  1922.         c->rp =c->window->RPort;
  1923.         c->Screen=c->window->WScreen;
  1924.         }
  1925.  
  1926.     c->FixedWidth =c->RealWidth =c->rp->Layer->bounds.MaxX-c->rp->Layer->bounds.MinX;
  1927.     c->FixedHeight=c->RealHeight=c->rp->Layer->bounds.MaxY-c->rp->Layer->bounds.MinY;
  1928.  
  1929.     c->left    = GetTagData(AMA_Left,0,tagList);
  1930.     c->bottom= GetTagData(AMA_Bottom,0,tagList);
  1931.  
  1932.  
  1933.     c->front_rp =c->rp;
  1934.     c->back_rp=NULL;
  1935. //    c->rp = c->front_rp;
  1936.  
  1937.  
  1938.     c->width = GetTagData(AMA_Width,c->RealWidth-c->left,tagList);
  1939.     c->height= GetTagData(AMA_Height,c->RealHeight-c->bottom,tagList);
  1940.  
  1941.     c->depth = GetBitMapAttr(c->rp->BitMap,BMA_DEPTH);
  1942.  
  1943. //    c->gl_ctx->BufferWidth = c->width;
  1944. //    c->gl_ctx->BufferHeight = c->height;
  1945.  
  1946.     c->pixel = 0;    /* current drawing pen */
  1947.  
  1948.     AllocCMap(c->Screen);
  1949.  
  1950.     if (c->visual->db_flag==GL_TRUE)
  1951.         {
  1952. DEBUGOUT("Dubelbuff inside amigastandard")
  1953.         if((c->back_rp = make_rastport(c->RealWidth,c->RealHeight,c->depth,c->rp->BitMap))!=NULL)
  1954.             {
  1955.             c->gl_ctx->Color.DrawBuffer = GL_BACK;
  1956.             c->rp = c->back_rp;
  1957.             }
  1958.         else
  1959.             {
  1960.             printf("make_rastport Faild\n");
  1961.             c->gl_ctx->Color.DrawBuffer = GL_FRONT;
  1962.             }
  1963.         }
  1964.     else
  1965.         {
  1966.         c->gl_ctx->Color.DrawBuffer = GL_FRONT;
  1967.         }
  1968.     AllocOneLine(c); /* A linebuffer for WritePixelLine */
  1969.  
  1970.     if (!make_temp_raster( c->rp ))
  1971.         printf("Error allocating TmpRastPort\n");
  1972.  
  1973.     alloc_temp_rastport(c);
  1974.     allocarea(c->rp);
  1975.  
  1976.     c->InitDD=amiga_standard_DD_pointers;  /*standard drawing*/
  1977.     c->Dispose=Amiga_Standard_Dispose;
  1978.     c->SwapBuffer=Amiga_Standard_SwapBuffer;
  1979.  
  1980.  
  1981. #ifdef DEBUGPRINT
  1982.     printf("c->RealWidth =%d\n",c->RealWidth);
  1983.     printf("c->RealHeight=%d\n",c->RealHeight);
  1984.     printf("c->width =%d\n",c->width);
  1985.     printf("c->height=%d\n",c->height);
  1986.     printf("c->left  =%d\n",c->left);
  1987.     printf("c->bottom=%d\n",c->bottom);
  1988.     printf("c->depth =%d\n",c->depth);
  1989. #endif
  1990.  
  1991.     return(TRUE);
  1992.     }
  1993. #endif    /* outdefines the whole file if ADISP_AGA isn't define*/